package handler;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;
import message.Receive;

public class ReceiveEncoder extends ChannelOutboundHandlerAdapter
{
    @Override
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception
    {
        Receive receive = (Receive) msg;
        ByteBuf buffer  = ctx.alloc().buffer();
        //空出报文头的写入空间
        buffer.writerIndex(4);
        receive.writeToMessage(buffer);
        ctx.write(buffer, promise);
    }
}
